package com.example.e_comm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.e_comm.entity.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    @Select("SELECT * FROM permissions p " +
            "INNER JOIN role_permission rp ON p.id = rp.perm_id " +
            "INNER JOIN user_role ur ON rp.role_id = ur.role_id " +
            "WHERE p.deleted = 0 AND ur.user_id = #{userId}")
    List<Permission> getPermissionByUserId(Long userId);

    @Select("SELECT * FROM permissions p " +
            "INNER JOIN role_permission rp ON p.id = rp.perm_id " +
            "WHERE rp.role_id = #{roleId} AND p.deleted = 0 ")
    List<Permission> getPermissionsByRoleId(Long roleId);
}